<?php
/**
*  data_controller
*/

class data_controller extends controller {
	protected $cache;
	
	public function __construct(){
			parent::__construct();
			$this->cache = Cache::getInstance();
	}
	
	public function index($value=''){
		if($this->isAjax()){
			$this->getAll();
		}
	}
	
	public function getAll($id = null){
		$this->view->setLayout('ajax');
		$user = new user();
		$data = $this->cache->get(md5('getAllData'));
		if(!$data) {
			$data = $user->findAllWithRelations(array('user_id','name','gender'));
			$this->cache->set(md5('getAllData'),$data);
		}
		
		$this->view->data = array("status"=>1,"data"=>$data);
		
		$this->render("response");
	}
	
	public function getPage($page = 0){
		$this->view->setLayout('ajax');
		$user = new user();
		$data = $this->cache->get(md5('getAllData'.$page));
		if(!$data) {
			$data = $user->findAllWithRelations(array('user_id','name','gender'));
			$this->cache->set(md5('getAllData'.$page),$data);
		}
		
		$this->view->data = $data;
		
		$this->render("response");
	}
}